画笔(Paint)
描述形状绘制方式,包括填充/描边样式、厚度、颜色、渐变与混合行为。
字段(Fields)
style
类型为 PaintStyle 的绘制样式。
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
style = 'stroke',
})
join
拐角连接方式,见 StrokeJoin。
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
cap = 'round',
style = 'stroke',
})
cap
端点样式,见 StrokeCap。
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
join = 'round',
style = 'stroke',
})
thickness
描边厚度。
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
thickness = 4,
style = 'stroke',
})
blendMode
合成混合模式。见 BlendMode。
feather
羽化强度。
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
feather = 4,
style = 'stroke',
})
gradient
应用于填充的 Gradient。
local g = Gradient.linear(Vector.xy(0, 0), Vector.xy(10, 0), {
{ position = 0, color = Color.rgb(255, 0, 0) },
{ position = 1, color = Color.rgb(0, 0, 255) },
})
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
gradient = g,
style = 'fill',
})
color
颜色。见 Color。
self.paint = Paint.with({
color = Color.rgb(255, 100, 50),
style = 'fill',
})
构造器(Constructors)
new
创建默认设置的新 Paint。
local paint = Paint.new()
paint.style = 'fill'
paint.color = Color.rgb(255, 200, 80)
with
根据 PaintDefinition 创建并初始化 Paint。
local strokePaint = Paint.with({
style = 'stroke',
thickness = 3,
color = Color.hex('#FF0066'),
join = 'round',
cap = 'round',
})
方法(Methods)
copy
返回当前 Paint 的副本,可选用 PaintDefinition 覆盖部分字段。
local base = Paint.with({
style = 'fill',
color = Color.rgb(255, 0, 0),
})
local outline = base:copy({
style = 'stroke',
thickness = 4,
})